/*
 * 上海远境文化传媒有限公司 版权所有
 */
package controllers.api.v1;

import controllers.api.v1.auth.ApiAuth;
import controllers.license.LicenseChecker;
import ext.auth.CheckUserRole;
import facade.AppContext;
import facade.open.BaseJsonAPI;
import facade.open.response.base.EntityLogResponse;
import models.base.Corp;
import models.base.EntityLog;
import models.enums.UserRole;
import play.Logger;
import play.mvc.With;

import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * 日志接口API.
 */
@With({ApiAuth.class, LicenseChecker.class})
@CheckUserRole("SuperAdmin")
public class EntityLogsAPI extends BaseJsonAPI {

    public static void index(String entityId) {
        Logger.info("LOG07013: view logs entityId = " + entityId);
        Corp corp = AppContext.currentCorp();
        List<EntityLog> entityLogs  = EntityLog.findByEntityId(corp, entityId);
        renderData(entityLogs.stream().map(EntityLogResponse::from).collect(toList()));
    }

}
